<?php
/**
 * 系统设置
 * Created by PhpStorm.
 * User: zhan
 * Date: 2018/8/2  10:29
 */

namespace app\admin\Controller;
use Doctrine\Common\Cache\MemcacheCache;
use think\Session;
use think\cache\driver\Redis;
class Set extends Common
{
    /*
    *	构造函数
    */
    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        if(request()->isAjax()){
            $poundage = input('poundage');
            $id = input('id/d');
            $data['poundage'] = $poundage;

            if(!empty($id)){
               $bool= db('config')->where('id=1')->update($data);
            }else{
                $data['id']=1;
               $bool= db('config')->insert($data);
            }
            if($bool)return $this->success('操作成功！');
            return $this->error('操作失败！');
        }
        $config = db('config')->where('id=1')->find();
        $config['poundage'] = rtrim(rtrim($config['poundage'], '0'), '.'); 
        $this->assign('config', $config);
        return $this->fetch();
    }

    public function agreement()
    {
        $db_agreement = db('agreement');
        if(request()->isAjax()){
            $title = input('title');
            $content = input('content');
            $status = input('status');
            $id = input('id/d');

            $data = [
                'title'=>$title,
                'content'=>$content,
                'status'=>$status,
            ];

            if(!empty($id)){
                $bool = $db_agreement->where('id='.$id)->update($data);
            }else{
                $data['id']=1;
                $bool = $db_agreement->insert($data);
            }

            if($bool)return $this->success('操作成功！');
            return $this->success('操作失败！');
        }
        $result = $db_agreement->where('id=1')->find();
        $this->assign('da', $result);
        return $this->fetch();
    }

    //购物注意
    public function protocol()
    {
        $db_agreement = db('protocol');
        if(request()->isAjax()){
            $title = input('title');
            $content = input('content');
            $id = input('id/d');

            $data = [
                'title'=>$title,
                'content'=>$content,
            ];

            if(!empty($id)){
                $bool = $db_agreement->where('id='.$id)->update($data);
            }else{
                $data['id']=1;
                $bool = $db_agreement->insert($data);
            }

            if($bool)return $this->success('操作成功！');
            return $this->success('操作失败！');
        }
        $result = $db_agreement->where('id=1')->find();
        $this->assign('da', $result);
        return $this->fetch();
    }
}
